﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using FBroSharp;
using FBroSharp.Callback;
using FBroSharp.Const;
using FBroSharp.DataType;
using FBroSharp.Event;
using FBroSharp.Lib;
using FBroSharp.Value;

namespace _007同步创建浏览器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //        FBroSharpControl.CreateSync("https://www.baidu.com", "baidu");
            //        public static FBroSharpBrowser CreateSync(string url, FBroSharpWindowsInfo windows_info, FBroSharpBrowserSetting browserset_info, FBroSharpRequestContext request, FBroSharpDictionaryValue extra_info, FBroSharpBrowserEvent @event, FBroSharpEventDisableControl event_contrl)
            //        {
            //            return CreateSync(url, windows_info, browserset_info, request, extra_info, @event, event_contrl, "");
            //        }

            FBroSharpWindowsInfo windows_info = new FBroSharpWindowsInfo { 
                //parent_window = IntPtr.Zero,
                parent_window = this.Handle,
                width = this.ClientSize.Width,
                height = this.ClientSize.Height,
                x = 0,
                y = 0
            };
            //浏览器事件回调
            FBroSharpBrowserEvent broser_event = new FBroSharpBrowserEvent();
            FBroSharpTask callback =   new CreateBrowserTask(
                "https://www.baidu.com",
                windows_info,
                default,
                default,
                default,
                broser_event,
                default

                );
            FBroSharpTaskRunner.CefPostTask(FBroSharpThreadID.TID_UI, callback);
        }

        public class CreateBrowserTask : FBroSharpTask
        {
            private string url;
            private FBroSharpWindowsInfo windows_info;
            private FBroSharpBrowserSetting browserset_info;
            private FBroSharpRequestContext request;
            private FBroSharpDictionaryValue extra_info;
            private FBroSharpBrowserEvent broser_event;
            private FBroSharpEventDisableControl event_contrl;

            public CreateBrowserTask(
                string url, 
                FBroSharpWindowsInfo windows_info, 
                FBroSharpBrowserSetting browserset_info, 
                FBroSharpRequestContext request, 
                FBroSharpDictionaryValue extra_info, 
                FBroSharpBrowserEvent broser_event,
                FBroSharpEventDisableControl event_contrl
                )
            {
                this.url = url;
                this.windows_info = windows_info;
                this.browserset_info = browserset_info;
                this.request = request;
                this.extra_info = extra_info;
                this.broser_event = broser_event;
                this.event_contrl = event_contrl;
            }
            public override void Execute()
            {
                FBroSharpControl.CreateSync(url, windows_info, browserset_info, request, extra_info, broser_event, event_contrl, "");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FBroSharpWindowsInfo windows_info = new FBroSharpWindowsInfo
            {
                parent_window = IntPtr.Zero,
                width = this.ClientSize.Width,
                height = this.ClientSize.Height,
                x = 0,
                y = 0
            };
            //浏览器事件回调
            FBroSharpBrowserEvent broser_event = new FBroSharpBrowserEvent();
            FBroSharpTask callback = new CreateBrowserTask(
                "https://www.baidu.com",
                windows_info,
                default,
                default,
                default,
                broser_event,
                default

                );
            FBroSharpTaskRunner.CefPostTask(FBroSharpThreadID.TID_UI, callback);
        }
    }
}
